package com.mmc.controller;


import com.mmc.entity.Content;
import com.mmc.entity.ContentCategory;
import com.mmc.entity.VO.ContentCategoryListVO;
import com.mmc.result.PageResult;
import com.mmc.result.R;
import com.mmc.service.IContentCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 内容分类 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-13
 */
@RestController
@RequestMapping("/admin/core/content-category")
@Api(tags = "广告类型")
public class ContentCategoryController {

    @Autowired
    private IContentCategoryService contentCategoryService;

    @PostMapping("/list")
    @ApiOperation("查询列表带分页")
    public R list(ContentCategoryListVO contentCategory)
    {
        PageResult<ContentCategory> list = contentCategoryService.selectContentCategoryList(contentCategory);
        return R.ok().data("rows",list);
    }
    /**
     * 新增广告内容分类
     */


    @PostMapping
    public R add(@RequestBody ContentCategory contentCategory)
    {
        contentCategoryService.save(contentCategory);
        return R.ok().message("添加删除");
    }

    /**
     * 修改广告内容分类
     */


    @PutMapping
    public R edit(@RequestBody ContentCategory contentCategory)
    {
        contentCategoryService.updateById(contentCategory);
        return R.ok().message("添加删除");
    }

    /**
     * 删除广告内容分类
     */

    @DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        List<Long> longs = Arrays.asList(ids);
        contentCategoryService.removeByIds(longs);
        return R.ok().message("添加删除");
    }

    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        ContentCategory byId = contentCategoryService.getById(id);
        return R.ok().data("data",byId);
    }

    @GetMapping("byContent")
    public R byContent()
    {
        List<ContentCategory> list = contentCategoryService.list();
        return R.ok().data("data",list);
    }
}
